<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>申请请假</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background-color: #f0f2f5;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input[type="number"],
        select,
        textarea {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        textarea {
            height: 100px;
            resize: vertical;
        }
        .buttons {
            display: flex;
            gap: 10px;
            justify-content: flex-end;
        }
        button {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button[type="submit"] {
            background-color: #1890ff;
            color: white;
        }
        button[type="submit"]:hover {
            background-color: #40a9ff;
        }
        .back-btn {
            background-color: #f0f0f0;
        }
        .back-btn:hover {
            background-color: #d9d9d9;
        }
        .temperature-input {
            position: relative;
            display: inline-block;
        }
        
        .temperature-input input {
            padding-right: 30px;
        }
        
        .temperature-unit {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            color: #666;
        }
        
        .course-selection {
            display: none;
            margin-top: 20px;
            padding: 20px;
            background: #f8f9fa;
            border-radius: 8px;
        }
        
        .course-selection.show {
            display: block;
        }
        
        .time-picker {
            display: flex;
            gap: 20px;
            align-items: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2><i class="fas fa-edit"></i> 上报体温</h2>
        <form action="/student/apply" method="post" id="leaveForm">
<!--            <div class="form-group">-->
<!--                <label for="leaveType">请假类型:</label>-->
<!--                <select id="leaveType" name="leaveType" required onchange="toggleTemperature()">-->
<!--                    <option value="SICK">病假</option>-->
<!--                    <option value="PERSONAL">事假</option>-->
<!--                </select>-->
<!--            </div>-->
            
            <div class="form-group" id="temperatureGroup">
                <label for="temperature">体温:</label>
                <div class="temperature-input">
                    <input type="number" id="temperature" name="temperature" 
                           step="0.1" min="35.0" max="42.0" required
                           placeholder="请输入体温">
                    <span class="temperature-unit">℃</span>
                </div>
            </div>
            
            <div class="form-group">
                <label for="description">请假原因:</label>
                <textarea id="description" name="description" required
                         placeholder="请详细描述病情或请假事由"></textarea>
            </div>
            
            <div class="form-group">
                <label for="leaveDate">请假日期:</label>
                <input type="date" id="leaveDate" name="leaveDate" required>
            </div>
            
            <div class="course-selection" id="courseSelection">
                <h3>选择请假课程时间</h3>
                <div class="time-picker">
                    <div class="form-group">
                        <label for="startSection">从第</label>
                        <select id="startSection" name="startSection" required>
                            <option value="">请选择</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                        </select>
                        <span>节</span>
                    </div>
                    
                    <div class="form-group">
                        <label for="endSection">到第</label>
                        <select id="endSection" name="endSection" required>
                            <option value="">请选择</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                        </select>
                        <span>节</span>
                    </div>
                </div>
                
                <div id="selectedCourses" class="selected-courses">
                    <!-- 这里会显示选中时间段的课程 -->
                </div>
            </div>
            
            <div class="buttons">
                <button type="button" class="back-btn" onclick="history.back()">返回</button>
                <button type="submit">提交申请</button>
            </div>
        </form>
    </div>
    
    <script>
        function toggleTemperature() {
            const leaveType = document.getElementById('leaveType').value;
            const temperatureGroup = document.getElementById('temperatureGroup');
            const temperature = document.getElementById('temperature');
            
            if (leaveType === 'SICK') {
                temperatureGroup.style.display = 'block';
                temperature.required = true;
            } else {
                temperatureGroup.style.display = 'none';
                temperature.required = false;
            }
        }
        
        document.getElementById('leaveDate').addEventListener('change', function() {
            document.getElementById('courseSelection').classList.add('show');
            // TODO: 根据选择的日期加载课程
        });
        
        // 监听开始和结束节次的变化
        document.getElementById('startSection').addEventListener('change', updateCourseDisplay);
        document.getElementById('endSection').addEventListener('change', updateCourseDisplay);
        
        function updateCourseDisplay() {
            const startSection = document.getElementById('startSection').value;
            const endSection = document.getElementById('endSection').value;
            const leaveDate = document.getElementById('leaveDate').value;
            
            if (startSection && endSection && leaveDate) {
                // TODO: 调用后端API获取该时间段的课程
                fetch(`/student/courses?date=${leaveDate}&start=${startSection}&end=${endSection}`)
                    .then(response => response.json())
                    .then(courses => {
                        // 显示课程信息
                        displaySelectedCourses(courses);
                    });
            }
        }
        
        function displaySelectedCourses(courses) {
            const container = document.getElementById('selectedCourses');
            // TODO: 显示选中时间段的课程信息
        }
        
        // 页面加载时执行一次
        toggleTemperature();
    </script>
</body>
</html> 